package stu.day1_day8;

public class LeetCode414 {
    public int thirdMax(int[] nums) {

        int MaxNum = -2147483648;
        int SecNmu = -2147483648;
        int ThrNmu = -2147483648;
        int len = 0;
        int max = 0;
        int sec = 0;
        int thr = 0;
        for(int i = 0;i < nums.length;i++){
            if(nums[i] < 2147483647){
                nums[i] = nums[i]+1;
            }
            if(nums[i]>MaxNum){
                ThrNmu = SecNmu;
                SecNmu = MaxNum;
                MaxNum = nums[i];
                len += 1;
                continue;
            }
            if(nums[i]>SecNmu && nums[i]<MaxNum){
                ThrNmu = SecNmu;
                SecNmu = nums[i];
                len += 1;
                continue;
            }
            if(nums[i]>ThrNmu && nums[i]<SecNmu && nums[i]<MaxNum){
                ThrNmu =nums[i];
                len += 1;
            }
        }

        if(len>=3){
            return ThrNmu-1;
        }else{
            return MaxNum-1;
        }

    }

    public static void main(String[] args) {

    }
}
